<?php
/**
 * 平台收货国家
 * User: bgl
 * Date: 2022/9/7
 * Time: 11:36
 */

namespace App\Admin\Controllers\Basics;

use App\Admin\Actions\Basics\SysPlatCountry\ImportCountry;
use App\Models\Basics\SysCountry;
use App\Models\Basics\SysPlatCountry;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;

class SysPlatCountryController extends AdminController {

    protected $title = '收货国家';

    protected function grid()
    {

        $grid = new Grid(new SysPlatCountry());
        $grid->column('id', 'ID');
        $grid->column('country_code', '收货国家');
        $grid->column('country_cn', '收货国家名称');
        $grid->column('country.country', '映射国家');
        $grid->actions(function (Grid\Displayers\Actions $actions) {
            $actions->disableView();
            $actions->disableDelete();
        });
        $grid->tools(function (Grid\Tools $tools) {
            $tools->append(new ImportCountry());
        });

        $grid->disableRowSelector();
        $grid->disableExport();
        $grid->filter(function($filter){
            $filter->column(1/3, function ($filter) {
                $filter->equal('id', '收货国家')->select(SysPlatCountry::options());
            });
            $filter->column(1/3, function ($filter){
                $filter->equal('country_id', '发货国家')->select(SysCountry::options());
            });
        });

        return $grid;
    }

    public function form()
    {
        $form = new Form(new SysPlatCountry());

        $form->hidden('id');
        $form->text('country_code', '收货国家编码')->rules('required');
        $form->text('country_cn', '收货国家名称');
        $form->select('country_id', '发货国家')->options(SysCountry::options())->rules('required');

        $form->tools(function (Form\Tools $tools) {
            $tools->disableView();
            $tools->disableDelete();
        });

        return $form;
    }

}
